package redis

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commEntityManager"
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedisRpc"
	"net/http"
	"time"
)

type redisScheduler struct {
}

func (e *redisScheduler) scheduler() {
	for true {
		if !commEntityManager.EntityManager.Initialized {
			time.Sleep(1 * time.Second)
			continue
		}

		requestVO, err := commRedisRpc.Manager.Server.Request.Pop(1 * time.Second)
		if err != nil {
			continue
		}

		respondVO := &commRedisRpc.RestFulRespondVO{}
		respondVO.BindRequestVO(requestVO)

		result, _, err := Handler.execute(requestVO)
		if err != nil {
			respondVO.Msg = err.Error()
			respondVO.Code = http.StatusInternalServerError
		} else {
			respondVO.Data = result
			respondVO.Code = http.StatusOK
		}

		// 检查是否需要返回数据：如果有UUID，说明客户端会根据UUID取数据
		if requestVO.Uuid != "" {
			commRedisRpc.Manager.Server.Respond.Push(respondVO.Uuid, respondVO)
		}
	}
}
